<template>
  <div class="addForm">
    <el-dialog title="增加特产" :visible="dialogFormVisible" @close="$emit('closeDialog')" width="50%">
      <el-form :label-position="labelPosition" label-width="150px" :model="addForm">
        <el-form-item label="特产id" :required="true">
          <el-input v-model="addForm.itemId"></el-input>
        </el-form-item>
        <el-form-item label="用户id" :required="false">
          <el-input v-model="addForm.userId"></el-input>
        </el-form-item>
        <el-form-item label="用户昵称" :required="false">
          <el-input v-model="addForm.userName"></el-input>
        </el-form-item>
        <el-form-item label="手机号" :required="true">
          <el-input v-model="addForm.phone"></el-input>
        </el-form-item>
        <el-form-item label="预约的时间" :required="true">
          <el-input v-model="addForm.thatDay"></el-input>
        </el-form-item>
        <el-form-item label="数量" :required="false">
          <el-input v-model="addForm.amount"></el-input>
        </el-form-item>
        <el-form-item label="单价" :required="false">
          <el-input v-model="addForm.price"></el-input>
        </el-form-item>

        <!-- <imgUpload @uploaded="uploaded" @uploadFail="uploadFail" :size="500"></imgUpload> -->
        <el-form-item label="状态(0:未领取 1:已领取 2:已过期)" :required="true">
          <el-input v-model="addForm.status"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="$emit('closeDialog')">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button> 
      </div>
    </el-dialog>
  </div>
</template>

<script>
// import imgUpload from "../imgUpload";
export default {
  name: "appointmentAdd",
  props: ["dialogFormVisible"],
  data() {
    return {
      labelPosition: "right",
      addForm: {
        itemId: "",
        userId: "",
        userName: "",
        phone: "",
        thatDay: "",
        amount: "",
        price: "",
        status:""
      },
      imageUrl: "",
      OldImageUrl: ""
      // uploadApi: "http://127.0.0.1:8000/api/img/uploadImg"
    };
  },
  methods: {
    submit: async function() {
      let data = await this._axios
        .post("/api/productAppointment/add", this.addForm)
        .then(data => data.data);
      console.log(data);
      if (data) {
        this.$alert(`${data.msg}`, {
          confirmButtonText: "确定",
          callback: () => {
            this.$message({
              type: "warning",
              message: `${data.msg}`
            });
            this.$emit("refresh");
          }
        });
        this.addForm = {
          itemId: "",
          userId: "",
          userName: "",
          phone: "",
          thatDay: "",
          amount: "",
          price: "",
          status:""

        };
      }
    }
    // uploaded: function(res) {
    //   console.log(this.OldImageUrl);
    //   this.OldImageUrl = this.addForm.avatar_url;
    //   this.addForm.main_img = res.path;
    // },
    // uploadFail: function(res) {
    //   console.log(res);
    //   //上传错误处理
    // }
  },
  components: {
    // imgUpload
  }
};
</script>

<style lang="scss">
.addForm {
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409eff;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
}
</style>